package com.example.new8.views;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.new8.R;
import com.example.new8.base.BaseActivity;
import com.example.new8.contract.NewsContact;
import com.example.new8.entity.WorldNews;
import com.example.new8.presenter.NewsPresenter;
import com.example.new8.utils.TimeUtils;

public class NewsActivity extends BaseActivity implements NewsContact.NewsView {
    private ImageView nImage ;
    private TextView nDate1 , nDate2 , nNews , nWeiyv ;
    private NewsContact.NewsPresenter presenter ;


    @Override
    public int getLayoutId() {
        return R.layout.activity_news;
    }

    @Override
    public void init() {
        nImage = findViewById(R.id.n_image) ;
        nDate1 = findViewById(R.id.n_date1) ;
        nDate2 = findViewById(R.id.n_date2) ;
        nNews = findViewById(R.id.n_news) ;
        nWeiyv = findViewById(R.id.n_weiyv) ;

        presenter = new NewsPresenter(this , this);
        presenter.getData();

        nDate1.setText("农历：\n" + TimeUtils.getTime()[1]);
        nDate2.setText(TimeUtils.getTime()[0]);
    }

    @Override
    public void showData(WorldNews data) {
        Glide.with(this)
                .load(data.getResult().getHeadImage())
                .centerCrop()
                .into(nImage);

        nNews.setText(getExplain(data.getResult().getNews()));

        nWeiyv.setText(data.getResult().getWeiyu());
    }

    private String getExplain(String[] array){
        StringBuilder sb = new StringBuilder();
        for (String s : array){
            sb.append(s + "\n\n");
        }
        return sb.toString();
    }
}